package band.wukong.practice.javase.core.net;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

/**
 * Created by IntelliJ IDEA.
 * User: Johnson
 * Date: 2012-8-24 15:58:33
 * To change this template use File | Settings | File Templates.
 */
public class ClientV1 {

    static Socket server;

    public static void main(String[] args) throws Exception {
        //1.获取server
        server = new Socket(InetAddress.getLocalHost(), 5678);

        //2.取得server输入
        BufferedReader in =
                new BufferedReader(
                        new InputStreamReader(server.getInputStream()));

        //3.取得server输出
        PrintWriter out = new PrintWriter(server.getOutputStream());

        //4.取得系统输入
        BufferedReader wt = new BufferedReader(new InputStreamReader(System.in));

        //5.开搞！
        while (true) {
            String str = wt.readLine();
            out.println(str);
            out.flush();
            if (str.equals("end")) {
                break;
            }
            System.out.println(in.readLine());
        }

        //6.打完收工
        server.close();
    }
}
